package com.twu.biblioteca;

public class Book {

    private final static String LIST_SEPARATOR = "  |  ";
    private static final String INVALID_YEAR_MESSAGE = "Year Entered was not in the Correct Format e.g 2014";
    private final String title;
    private final String author;
    private final String yearPublished;
    private boolean checkedOut;

    public Book(String title, String author, String yearPublished) {
        this.title = title;
        this.author = author;
        this.checkedOut = false;

        if (yearPublished.matches("[0-9]{4}?")) // Year in format XXXX
            this.yearPublished = yearPublished;
        else
            throw new IllegalArgumentException(INVALID_YEAR_MESSAGE);
    }

    public String getAuthor() {
        return author;
    }

    public String getYearPublished() {
        return yearPublished;
    }

    public String getTitle() {
        return title;
    }

    public boolean isCheckedOut() {
        return checkedOut;
    }

    public void setCheckedOut(boolean checkedOut) {
        this.checkedOut = checkedOut;
    }

    @Override
    public String toString() {
        return "Title: '" + title + "'" + Book.LIST_SEPARATOR +
                "Author: '" + author + "'" + Book.LIST_SEPARATOR +
                "Published: '" + yearPublished + "'";
    }

    public boolean compareWithDetails(String title, String author, String year) {
        return (this.getTitle().equalsIgnoreCase(title) &&
                this.getAuthor().equalsIgnoreCase(author) &&
                this.getYearPublished().equalsIgnoreCase(year));
    }
}
